#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time

class SpiderRobot:
########ID列表 L1 L3 R1 R3 #######
	_ids = []

########等待时间定义#######
	TIME_SHORT=0.3  #前进、后退左右转
	TIME_LONG=0.7   #打招呼、做运动、跳舞、蹲下起立

########协议传感器开关#######
	SENSOR_ON = [1]
	SENSOR_OFF = [0]

########速度#######
	SPEED = 30
	SPEED2 = [SPEED,SPEED]
	SPEED4 = [SPEED,SPEED,SPEED,SPEED]
	SPEED6 = [SPEED,SPEED,SPEED,SPEED,SPEED,SPEED]
	SPEED8 = [SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED]
	SPEED12 = [SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED]

########蹲下站立########
	STAND_UP = 80
	STAND_DOWN = 20

########打招呼########
	HELLO_HAND_HIGH = 20
	HELLO_HAND_LOW = 20
	HELLO_LEG_HIGH = 50
	HELLO_LEG_LOW = 0

	leg03 = []
	leg_RArmFour = []

########俯卧撑########
	SPORT_UP = -80
	SPORT_DOWN = -30

########跳舞########
	DANCE_UP = -90
	DANCE_DOWN = -35

	# leg_danceFour = [29,33,39,35]
	leg_danceFour = [  ]

########同时控制两条腿########
	# leg05 = [ 28,29,38,39 ]
	# leg23 = [ 32,33,34,35]
	# leg0235 = [ 28,29,32,33,34,35,38,39 ]
	leg05 = [  ]
	leg23 = [  ]
	leg0235 = [  ]

########################初始化位置########################
	STEP_INIT = [ 0 , -90 , 0 , -90 ,0 , -90 ]

	#立行
	STEP_UP = 50
	STEP_TURN = 30
	STEP_DOWN = 90

	#匍匐
	D_STEP_UP = 10
	D_STEP_TURN = 30
	D_STEP_DOWN = 30

########################前进步态########################
########TT4腿蜘蛛前进########
	FORWARD_UP = [0,-STEP_UP,0,-STEP_UP ]
	FORWARD_DOWN = [ -STEP_TURN,-STEP_DOWN,STEP_TURN,-STEP_DOWN ]
	FORWARD_INIT = [ 0,-STEP_DOWN,0,-STEP_DOWN ]
	FORWARD_05_23 = [0,-STEP_DOWN , -STEP_TURN,-STEP_UP,  STEP_TURN,-STEP_UP,  0,-STEP_DOWN ]  #05腿恢复，23腿转
	FORWARD_23_05 = [ -STEP_TURN,-STEP_UP ,  0,-STEP_DOWN,  0,-STEP_DOWN, STEP_TURN,-STEP_UP ] #23恢复，05转

##匍匐前进
	D_FORWARD_UP = [0,-D_STEP_UP,0,-D_STEP_UP ]
	D_FORWARD_DOWN = [ -D_STEP_TURN,-D_STEP_DOWN,D_STEP_TURN,-D_STEP_DOWN ]
	D_FORWARD_INIT = [ 0,-D_STEP_DOWN,0,-D_STEP_DOWN ]
	D_FORWARD_05_23 = [0,-D_STEP_DOWN , -D_STEP_TURN,-D_STEP_UP,  D_STEP_TURN,-D_STEP_UP,  0,-D_STEP_DOWN ]#05腿恢复，23腿转
	D_FORWARD_23_05 = [ -D_STEP_TURN,-D_STEP_UP ,  0,-D_STEP_DOWN,  0,-D_STEP_DOWN, D_STEP_TURN,-D_STEP_UP ]#23恢复，05转

########################后退步态########################
########TT4腿蜘蛛后退########
	BACK_UP = [ 0,-STEP_UP,0,-STEP_UP ]
	BACK_DOWN = [ STEP_TURN,-STEP_DOWN,-STEP_TURN,-STEP_DOWN ]
	BACK_INIT = [ 0,-STEP_DOWN,0,-STEP_DOWN ]
	BACK_05_23 = [ 0,-STEP_DOWN ,  STEP_TURN,-STEP_UP,  -STEP_TURN,-STEP_UP,  0,-STEP_DOWN ]#05腿恢复，23腿转
	BACK_23_05 = [ STEP_TURN,-STEP_UP ,  0,-STEP_DOWN,  0,-STEP_DOWN, -STEP_TURN,-STEP_UP ]#23恢复，05转

########TT4腿蜘蛛匍匐后退########
	D_BACK_UP = [ 0,-D_STEP_UP,0,-D_STEP_UP ]
	D_BACK_DOWN = [ D_STEP_TURN,-D_STEP_DOWN,-D_STEP_TURN,-D_STEP_DOWN ]
	D_BACK_INIT = [ 0,-D_STEP_DOWN,0,-D_STEP_DOWN ]
	D_BACK_05_23 = [ 0,-D_STEP_DOWN ,  D_STEP_TURN,-D_STEP_UP,  -D_STEP_TURN,-D_STEP_UP,  0,-D_STEP_DOWN ]#05腿恢复，23腿转
	D_BACK_23_05 = [ D_STEP_TURN,-D_STEP_UP ,  0,-D_STEP_DOWN,  0,-D_STEP_DOWN, -D_STEP_TURN,-D_STEP_UP ]#23恢复，05转

########################向左步态########################
########TT4腿蜘蛛自转步态向左########
	TURN_LUP = [0,-STEP_UP,0,-STEP_UP ]
	TURN_LTURN = [ STEP_TURN,-STEP_UP, STEP_TURN,-STEP_UP ]
	TURN_LDOWN = [ STEP_TURN,-STEP_DOWN, STEP_TURN,-STEP_DOWN ]

########TT4腿蜘蛛匍匐自转步态向左########
	D_TURN_LUP = [0,-D_STEP_UP,0,-D_STEP_UP ]
	D_TURN_LTURN = [ STEP_TURN,-D_STEP_UP, STEP_TURN,-D_STEP_UP ]
	D_TURN_LDOWN = [ STEP_TURN,-D_STEP_DOWN, STEP_TURN,-D_STEP_DOWN ]

########################向右步态########################
########TT4腿蜘蛛自转步态向右########
	TURN_RUP = [ 0,-STEP_UP,0,-STEP_UP ]
	TURN_RTURN = [ -STEP_TURN,-STEP_UP, -STEP_TURN,-STEP_UP ]
	TURN_RDOWN = [- STEP_TURN,-STEP_DOWN, -STEP_TURN,-STEP_DOWN ]

########TT4腿蜘蛛匍匐自转步态向右########
	D_TURN_RUP = [ 0,-D_STEP_UP,0,-D_STEP_UP ]
	D_TURN_RTURN = [ -STEP_TURN,-D_STEP_UP, -STEP_TURN,-D_STEP_UP ]
	D_TURN_RDOWN = [- STEP_TURN,-D_STEP_DOWN, -STEP_TURN,-D_STEP_DOWN ]

########################做动作表演########################
########TT4腿蜘蛛蹲下站立########
	STAND_UP_STEPS = [ 0,-STAND_UP,0,-STAND_UP, 0,-STAND_UP, 0,-STAND_UP ]
	STAND_DOWN_STEPS = [ 0,-STAND_DOWN,0,-STAND_DOWN, 0,-STAND_DOWN, 0,-STAND_DOWN]

########TT4腿蜘蛛打招呼########
	HELLO_INIT = [-70,-65,10,-65,0,10,-10,-65]
	HELLO_TURN_LEFT = [HELLO_HAND_HIGH,HELLO_LEG_HIGH ]
	HELLO_TURN_RIGHT = [-HELLO_HAND_LOW,HELLO_LEG_HIGH ]	
	HELLO_HAND_UP = [0,HELLO_LEG_HIGH ]
	HELLO_HAND_DOWN = [0,HELLO_LEG_LOW ]

########TT４腿蜘蛛俯卧撑########
	SPORT_INIT = [ 45,SPORT_UP,45, -30, -45,SPORT_UP,-45, -30 ]
	SPORT_UP_STEPS = [45,SPORT_UP, -45, SPORT_UP ]
	SPORT_DOWN_STEPS = [ 45,SPORT_DOWN, -45, SPORT_DOWN ]

	SPORT_INIT_ONE =[-75,-65,25,-30,0,10,-25,-30]#单手俯卧撑
	SPORT_INIT_ONE_DOWN =[-75,-20,25,-30,0,10,-25,-30]#单手俯卧撑下去

########TT4腿蜘蛛跳舞########
	DANCE_ONE = [ DANCE_UP,DANCE_DOWN,DANCE_DOWN,DANCE_DOWN ]
	DANCE_TWO = [ DANCE_DOWN,DANCE_UP,DANCE_DOWN, DANCE_DOWN ]
	DANCE_THREE = [ DANCE_DOWN,DANCE_DOWN,DANCE_DOWN,DANCE_UP ]
	DANCE_FOUR = [ DANCE_DOWN,DANCE_DOWN,DANCE_UP,DANCE_DOWN ]

########TT4腿蜘蛛防御动作演示########
	HANG_TAIL_TURN_1 = 25
	HANG_TAIL_TURN_2 = 75
	HANG_TAIL_BLEG_STAND = 90
	BATTLE_STAND = 90
	BATTLE_STAND_INIT = 80
	BATTLE_SIT = 65
	MOVE_BODY_TURN = 45
	
	HANG_TAIL_INIT = [-45,0,45,-HANG_TAIL_BLEG_STAND,45,0,-45,-HANG_TAIL_BLEG_STAND] 
	HANG_TAIL_LEFT = [-45,0,HANG_TAIL_TURN_1,-90,45,0,-HANG_TAIL_TURN_2,-90]
	HANG_TAIL_RIGHT = [-45,0,HANG_TAIL_TURN_2,-90,45,0,-HANG_TAIL_TURN_1,-90]
	BATTLE_INIT = [-45,-BATTLE_STAND_INIT,45,-BATTLE_STAND_INIT,45,-BATTLE_STAND_INIT,-45,-BATTLE_STAND_INIT]
	BATTLE_FORWARD = [-45,-BATTLE_SIT,45,-BATTLE_STAND,45,-BATTLE_SIT,-45,-BATTLE_STAND]
	BATTLE_BACK = [-45,-BATTLE_STAND,45,-BATTLE_SIT,45,-BATTLE_STAND,-45,-BATTLE_SIT]
	MOVE_BODY_LTURN = [MOVE_BODY_TURN,-90,MOVE_BODY_TURN,-90,MOVE_BODY_TURN,-90,MOVE_BODY_TURN,-90]
	MOVE_BODY_RTURN = [-MOVE_BODY_TURN,-90,-MOVE_BODY_TURN,-90,-MOVE_BODY_TURN,-90,-MOVE_BODY_TURN,-90]

	scanned_ids=[]
	init_position=[]
	moving_count = 0

    #########RGB彩灯
	SENSOR_RGB = [[255,1,1],[1,255,1],[1,1,255],[255,255,1],[255,1,255],[1,255,255],[255,255,255],[255,100,1],[1,1,1]]


	#初始化机器人：使用 BwRobotLib 对象
	def __init__(self,robotlib):
		self.robotlib = robotlib
		self.lib = self.robotlib.mclib

    #绑定ID： T T IU (F) T T IU
	def bindIds(self,ids):
		self._ids = ids
		# self._ids = [30,31,32,33,36,35,38,39]
		self.leg03 = [ self._ids[0],self._ids[1],self._ids[4],self._ids[5] ]
		self.leg_RArmFour = [self._ids[4],self._ids[5]]
		self.leg23 = [ self._ids[2],self._ids[3],self._ids[4],self._ids[5] ]
		self.leg05 = [ self._ids[0],self._ids[1],self._ids[6],self._ids[7] ]
		self.leg0235 = [self._ids[0],self._ids[1],self._ids[2],self._ids[3], self._ids[4],self._ids[5],self._ids[6],self._ids[7]]
		self.leg_danceFour = [ self._ids[1],self._ids[3],self._ids[5],self._ids[7] ]
		#self.scanned_ids = self.lib.ScanId(0,50)
		#print(self.scanned_ids[0]) 
		#四腿蜘蛛
		for a in range(0,8):  
			self.lib.SetMotorMode(self._ids[a],0)
		self.init_position = [ 0,-70,0,-70,0,-70,0,-70]	
		# del self.scanned_ids[0][0]	
		res=self.lib.SetMotorPositionSync(self._ids,self.init_position)
		time.sleep(self.TIME_SHORT)
		if(res > 0):
			print("机器人初始化设置成功")
		else:
			print("机器人初始化设置失败")


	###快速初始化
	def quickInit(self):
		self.lib.SetMotorPositionSync(self._ids,self.init_position)
		time.sleep(self.TIME_LONG)

	###四腿蜘蛛前进步态
	def goForward(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.FORWARD_UP,self.SPEED4)#05脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.FORWARD_23_05,self.SPEED8)#23腿恢复（脚尖不动），同时05向前迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.FORWARD_DOWN,self.SPEED4)#05脚落下
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self. FORWARD_UP,self.SPEED4)#23脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.FORWARD_05_23,self.SPEED8)#05腿恢复（脚尖不动），同时23向前迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.FORWARD_DOWN,self.SPEED4)#23脚落下
		time.sleep(0.3)	

    ###四腿蜘蛛匍匐前进步态
	def goForward_down(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.D_FORWARD_UP,self.SPEED4)#05脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.D_FORWARD_23_05,self.SPEED8)#23腿恢复（脚尖不动），同时05向前迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.D_FORWARD_DOWN,self.SPEED4)#05脚落下
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_FORWARD_UP,self.SPEED4)#23脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.D_FORWARD_05_23,self.SPEED8)#05腿恢复（脚尖不动），同时23向前迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_FORWARD_DOWN,self.SPEED4)#23脚落下
		time.sleep(0.3)	

	###四腿蜘蛛后退步态
	def goBack(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.BACK_UP,self.SPEED4)#05脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.BACK_23_05,self.SPEED8)#23腿恢复（脚尖不动），同时05向后迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.BACK_DOWN,self.SPEED4)#05脚落下
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self. BACK_UP,self.SPEED4)#23脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self. BACK_05_23,self.SPEED8)#05腿恢复（脚尖不动），同时23向后迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.BACK_DOWN,self.SPEED4)#23脚落下
		time.sleep(0.3)

	###四腿蜘蛛匍匐后退步态
	def goBack_down(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.D_BACK_UP,self.SPEED4)#05脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.D_BACK_23_05,self.SPEED8)#23腿恢复（脚尖不动），同时05向后迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.D_BACK_DOWN,self.SPEED4)#05脚落下
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_BACK_UP,self.SPEED4)#23脚抬起
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.D_BACK_05_23,self.SPEED8)#05腿恢复（脚尖不动），同时23向后迈
		time.sleep(0.3)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_BACK_DOWN,self.SPEED4)#23脚落下
		time.sleep(0.3)

	###四腿蜘蛛原地向右转圈
	def turnRight(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.TURN_RUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self. TURN_RTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.TURN_RDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.TURN_RUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self. TURN_RTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.TURN_RDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)

	###四腿蜘蛛匍匐原地向右转圈
	def turnRight_down(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.D_FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.D_TURN_RUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self. D_TURN_RTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.D_TURN_RDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_TURN_RUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self. D_TURN_RTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_TURN_RDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)

	###四腿蜘蛛原地向左转圈
	def turnLeft(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.TURN_LUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self. TURN_LTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.TURN_LDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.TURN_LUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self. TURN_LTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.TURN_LDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)

	###四腿蜘蛛匍匐原地向左转圈
	def turnLeft_down(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05,self.D_FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_FORWARD_INIT,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.D_TURN_LUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self. D_TURN_LTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg05, self.D_TURN_LDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_TURN_LUP,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self. D_TURN_LTURN,self.SPEED4)
		time.sleep(self.TIME_SHORT)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg23, self.D_TURN_LDOWN,self.SPEED4) 
		time.sleep(self.TIME_SHORT)

	###四腿蜘蛛蹲下起立
	def doUpAndDown(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.STAND_DOWN_STEPS,self.SPEED8) 
		time.sleep(0.7)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.STAND_UP_STEPS,self.SPEED8)
		time.sleep(0.7)

	###四腿蜘蛛打招呼
	def sayHello(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.HELLO_INIT,self.SPEED8) 
		time.sleep(self.TIME_LONG)
		for SayhelloCount1 in range(0,2):
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_RArmFour, self.HELLO_TURN_LEFT,self.SPEED2) 
			time.sleep(0.7)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_RArmFour, self.HELLO_TURN_RIGHT,self.SPEED2) 
			time.sleep(0.7)
		for SayhelloCount2 in range(0,2):
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_RArmFour, self.HELLO_HAND_UP,self.SPEED2) 
			time.sleep(0.7)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_RArmFour, self.HELLO_HAND_DOWN,self.SPEED2) 
			time.sleep(0.7)

	###四腿蜘蛛俯卧撑		
	def doSport(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.SPORT_INIT,self.SPEED8) 
		time.sleep(0.5)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg03, self.SPORT_UP_STEPS,self.SPEED4)
		time.sleep(0.5)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg03, self.SPORT_DOWN_STEPS,self.SPEED4)
		time.sleep(0.5)

	###四腿单手蜘蛛俯卧撑	
	def doSport_oneHand(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.SPORT_INIT_ONE,self.SPEED8) 
		time.sleep(0.5)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.SPORT_INIT_ONE_DOWN,self.SPEED8)
		time.sleep(0.5)
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.SPORT_INIT_ONE,self.SPEED8)
		time.sleep(0.5)

	###四腿蜘蛛跳舞
	def dance(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.STAND_UP_STEPS,self.SPEED8)
		time.sleep(0.6)
		for a in range(0,3):
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_danceFour, self.DANCE_ONE,self.SPEED4) 
			time.sleep(0.6)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_danceFour, self.DANCE_TWO,self.SPEED4)
			time.sleep(0.6)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_danceFour, self.DANCE_THREE,self.SPEED4)
			time.sleep(0.6) 
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg_danceFour, self.DANCE_FOUR,self.SPEED4)
			time.sleep(0.6) 

######防御机器人######
	###四腿蜘蛛摇尾巴　
	def doHangTail(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.HANG_TAIL_INIT,self.SPEED8) 
		time.sleep(0.7)
		for a in range (0,3):
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.HANG_TAIL_LEFT,self.SPEED8)
			time.sleep(0.7)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.HANG_TAIL_RIGHT,self.SPEED8)
			time.sleep(0.7) 
 		
	###四腿蜘蛛战斗防御　
	def doBattle(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.BATTLE_INIT,self.SPEED8) 
		time.sleep(self.TIME_LONG)
		for a in range (0,4):
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.BATTLE_FORWARD,self.SPEED8)
			time.sleep(0.55)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.BATTLE_BACK,self.SPEED8)
			time.sleep(0.55) 

	###四腿蜘蛛扭动身体防御 
	def doMoveBody(self):
		self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.init_position,self.SPEED8) 
		time.sleep(0.7)
		for a in range (0,3):
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.MOVE_BODY_LTURN,self.SPEED8)
			time.sleep(0.8)
			self.lib.SetMotorPositionSyncWithSpeeds(self.leg0235, self.MOVE_BODY_RTURN,self.SPEED8)
			time.sleep(0.8) 

	###四足蜘蛛前进、后退、左转、右转各两个循环  
	def runDemo(self):
		count = 3
		delay = 0.5
		count1 = 3
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[0])
		for self.moving_count in range(0,count):
			print('向前走')
			self.goForward()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[1])
		for self.moving_count in range(0,count):
			print('向后走')
			self.goBack()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[2])
		for self.moving_count in range(0,count):
			print('向左转向')
			self.turnLeft()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[3])
		for self.moving_count in range(0,count):
			print('向右转向')
			self.turnRight()
		time.sleep(delay)
		self.quickInit()
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[4])
		for self.moving_count in range(0,count1):
			print('跳舞')
			self.dance()
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[5])
		for self.moving_count in range(0,count1):
			print('打招呼')
			self.sayHello()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[6])
		for self.moving_count in range(0,count1):
			print('蹲下起立')
			self.doUpAndDown()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[7])
		for self.moving_count in range(0,count1):
			print('俯卧撑')
			self.doSport()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[8])
		for self.moving_count in range(0,count1):
			print('单手俯卧撑')
			self.doSport_oneHand()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[0])
		for self.moving_count in range(0,count1):
			print('摇尾巴')
			self.doHangTail()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[1])
		for self.moving_count in range(0,count1):
			print('战斗')
			self.doBattle()
		time.sleep(delay)
		self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[2])
		for self.moving_count in range(0,count1):
			print('扭动身体')
			self.doMoveBody()

##############手势控制机器人
	def runGestureRemoteRobot(self):
		count = 3
		count1 = 2
		delay = 0.5
		while 1:
			print("请输入手势:")
			s3 = self.lib.SetSensorData(12,0x01,self.SENSOR_ON)
			s1 = self.lib.GetDevData(12,0x01)
			print ("返回值：",s1)
			if(s1==1):
			    #从下到上
			    self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[0])
			    print("正常活动")
			    for a in range(0,count1):
			    	print('向前走')
			    	self.goForward()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('向后走')
			    	self.goBack()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('向左转向')
			    	self.turnLeft()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('向右转向')
			    	self.turnRight()
			    time.sleep(delay)
			    self.quickInit()
			if(s1==2):
			    #从上到下
			    self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[1])
			    print("匍匐活动")
			    for a in range(0,count1):
			    	print('匍匐向前走')
			    	self.goForward_down()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('匍匐向后走')
			    	self.goBack_down()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('匍匐向左转向')
			    	self.turnLeft_down()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('匍匐向右转向')
			    	self.turnRight_down()
			    time.sleep(delay)
			    self.quickInit()
			if(s1==3):#从右到左
			    self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[2])
			    print("做运动")
			    for a in range(0,count):
			    	print('蹲下起立')
			    	self.doUpAndDown()
			    time.sleep(delay)
			    for a in range(0,count):
			    	print('单手俯卧撑')
			    	self.doSport_oneHand()
			    time.sleep(delay)
			    for a in range(0,count):
			    	print('俯卧撑')
			    	self.doSport()
			    time.sleep(delay)
			    for a in range(0,count1):
			    	print('跳舞')
			    	self.dance()
			    time.sleep(delay)
			    self.quickInit()
			if(s1==4):#从左到右
			    self.lib.SetSensorData(8,0x02,self.SENSOR_RGB[3])
			    print("玩耍动作")
			    for a in range(0,count):
			    	print('打招呼')
			    	self.sayHello()
			    for a in range(0,count):
			    	print('摇尾巴')
			    	self.doHangTail()
			    time.sleep(delay)
			    for a in range(0,count):
			    	print('战斗')
			    	self.doBattle()
			    time.sleep(delay)
			    for a in range(0,count):
			    	print('扭动身体')
			    	self.doMoveBody()	
			    self.quickInit()

